﻿<span style='font-size:11px; color:#000000; background:#ffffff; '><pre>
<span style='color:#800000; font-weight:bold; '>protected</span> <span style='color:#800000; font-weight:bold; '>void</span> createPdfButton_Click<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>object</span> sender<span style='color:#808030; '>,</span> EventArgs e<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#696969; '>// Create a PDF document</span>
    Document pdfDocument <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> Document<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set license key received after purchase to use the converter in licensed mode</span>
    <span style='color:#696969; '>// Leave it not set to use the converter in demo mode</span>
    pdfDocument<span style='color:#808030; '>.</span>LicenseKey <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add a PDF page to PDF document</span>
    PdfPage pdfPage <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>AddPage<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    HtmlToPdfElement htmlToPdfElement <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>null</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>try</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// Add a default document header</span>
        AddHeader<span style='color:#808030; '>(</span>pdfDocument<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a default document footer</span>
        AddFooter<span style='color:#808030; '>(</span>pdfDocument<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Create a HTML to PDF element to add to document</span>
        htmlToPdfElement <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> HtmlToPdfElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> urlTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Optionally set a delay before conversion to allow asynchonous scripts to finish</span>
        htmlToPdfElement<span style='color:#808030; '>.</span>ConversionDelay <span style='color:#808030; '>=</span> <span style='color:#008c00; '>2</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Install a handler where to change the header and footer in pages generated by the HTML to PDF element</span>
        htmlToPdfElement<span style='color:#808030; '>.</span>PrepareRenderPdfPageEvent <span style='color:#808030; '>+</span><span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> PrepareRenderPdfPageDelegate<span style='color:#808030; '>(</span>htmlToPdfElement_PrepareRenderPdfPageEvent<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add the HTML to PDF element to document</span>
        <span style='color:#696969; '>// This will raise the PrepareRenderPdfPageEvent event where the header can be changed per page</span>
        pdfPage<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>htmlToPdfElement<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Save the PDF document in a memory buffer</span>
        <span style='color:#800000; font-weight:bold; '>byte</span><span style='color:#808030; '>[</span><span style='color:#808030; '>]</span> outPdfBuffer <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Save<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Send the PDF as response to browser</span>

        <span style='color:#696969; '>// Set response content type</span>
        Response<span style='color:#808030; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Content-Type</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>application/pdf</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Instruct the browser to open the PDF file as an attachment or inline</span>
        Response<span style='color:#808030; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Content-Disposition</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>attachment; filename=Change_Header_Footer_Per_Page.pdf; size={0}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> outPdfBuffer<span style='color:#808030; '>.</span>Length<span style='color:#808030; '>.</span>ToString<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Write the PDF document buffer to HTTP response</span>
        Response<span style='color:#808030; '>.</span>BinaryWrite<span style='color:#808030; '>(</span>outPdfBuffer<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// End the HTTP response and stop the current page processing</span>
        Response<span style='color:#808030; '>.</span>End<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#800000; font-weight:bold; '>finally</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// uninstall handler</span>
        htmlToPdfElement<span style='color:#808030; '>.</span>PrepareRenderPdfPageEvent <span style='color:#808030; '>-</span><span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> PrepareRenderPdfPageDelegate<span style='color:#808030; '>(</span>htmlToPdfElement_PrepareRenderPdfPageEvent<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Close the PDF document</span>
        pdfDocument<span style='color:#808030; '>.</span>Close<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>

<span style='color:#696969; '>/// &lt;summary></span>
<span style='color:#696969; '>/// The handler for HtmlToPdfElement.PrepareRenderPdfPageEvent event where you can set the visibility of header and footer</span>
<span style='color:#696969; '>/// in each page or you can add a custom header or footer in a page</span>
<span style='color:#696969; '>/// &lt;/summary></span>
<span style='color:#696969; '>/// &lt;param name="eventParams">The event parameter containin the PDF page to customize before rendering&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>void</span> htmlToPdfElement_PrepareRenderPdfPageEvent<span style='color:#808030; '>(</span>PrepareRenderPdfPageParams eventParams<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span>eventParams<span style='color:#808030; '>.</span>PageNumber <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> &amp;&amp; changeHeaderAndFooterCheckBox<span style='color:#808030; '>.</span>Checked<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// Change the header and footer in first page with an alternative header and footer</span>

        <span style='color:#696969; '>// The PDF page being rendered</span>
        PdfPage pdfPage <span style='color:#808030; '>=</span> eventParams<span style='color:#808030; '>.</span>Page<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a custom header of 80 points in height to this page</span>
        <span style='color:#696969; '>// The default document header will be replaced in this page</span>
        pdfPage<span style='color:#808030; '>.</span>AddHeaderTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>80</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        <span style='color:#696969; '>// Draw the page header elements</span>
        DrawAlternativePageHeader<span style='color:#808030; '>(</span>pdfPage<span style='color:#808030; '>.</span>Header<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add a custom footer of 80 points in height to this page</span>
        <span style='color:#696969; '>// The default document footer will be replaced in this page</span>
        pdfPage<span style='color:#808030; '>.</span>AddFooterTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>80</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        <span style='color:#696969; '>// Draw the page header elements</span>
        DrawAlternativePageFooter<span style='color:#808030; '>(</span>pdfPage<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>

<span style='color:#696969; '>/// &lt;summary></span>
<span style='color:#696969; '>/// Add a header to document</span>
<span style='color:#696969; '>/// &lt;/summary></span>
<span style='color:#696969; '>/// &lt;param name="pdfDocument">The PDF document object&lt;/param></span>
<span style='color:#696969; '>/// &lt;param name="drawHeaderLine">A flag indicating if a line should be drawn at the bottom of the header&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>private</span> <span style='color:#800000; font-weight:bold; '>void</span> AddHeader<span style='color:#808030; '>(</span>Document pdfDocument<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>bool</span> drawHeaderLine<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>string</span> headerHtmlUrl <span style='color:#808030; '>=</span> Server<span style='color:#808030; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>~/DemoAppFiles/Input/HTML_Files/Header_HTML.html</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Create the document header template</span>
    pdfDocument<span style='color:#808030; '>.</span>AddHeaderTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>60</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Create a HTML element to be added in header</span>
    HtmlToPdfElement headerHtml <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> HtmlToPdfElement<span style='color:#808030; '>(</span>headerHtmlUrl<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set the HTML element to fit the container height</span>
    headerHtml<span style='color:#808030; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add HTML element to header</span>
    pdfDocument<span style='color:#808030; '>.</span>Header<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>headerHtml<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>drawHeaderLine<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#800000; font-weight:bold; '>float</span> headerWidth <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Header<span style='color:#808030; '>.</span>Width<span style='color:#800080; '>;</span>
        <span style='color:#800000; font-weight:bold; '>float</span> headerHeight <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Header<span style='color:#808030; '>.</span>Height<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Create a line element for the bottom of the header</span>
        LineElement headerLine <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> headerWidth<span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Set line color</span>
        headerLine<span style='color:#808030; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Gray<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add line element to the bottom of the header</span>
        pdfDocument<span style='color:#808030; '>.</span>Header<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>headerLine<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>

<span style='color:#696969; '>/// &lt;summary></span>
<span style='color:#696969; '>/// Add a footer to document</span>
<span style='color:#696969; '>/// &lt;/summary></span>
<span style='color:#696969; '>/// &lt;param name="pdfDocument">The PDF document object&lt;/param></span>
<span style='color:#696969; '>/// &lt;param name="addPageNumbers">A flag indicating if the page numbering is present in footer&lt;/param></span>
<span style='color:#696969; '>/// &lt;param name="drawFooterLine">A flag indicating if a line should be drawn at the top of the footer&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>private</span> <span style='color:#800000; font-weight:bold; '>void</span> AddFooter<span style='color:#808030; '>(</span>Document pdfDocument<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>bool</span> addPageNumbers<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>bool</span> drawFooterLine<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>string</span> footerHtmlUrl <span style='color:#808030; '>=</span> Server<span style='color:#808030; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>~/DemoAppFiles/Input/HTML_Files/Footer_HTML.html</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Create the document footer template</span>
    pdfDocument<span style='color:#808030; '>.</span>AddFooterTemplate<span style='color:#808030; '>(</span><span style='color:#008c00; '>60</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set footer background color</span>
    RectangleElement backColorRectangle <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> RectangleElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>Width<span style='color:#808030; '>,</span> pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>Height<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    backColorRectangle<span style='color:#808030; '>.</span>BackColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>WhiteSmoke<span style='color:#800080; '>;</span>
    pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>backColorRectangle<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Create a HTML element to be added in footer</span>
    HtmlToPdfElement footerHtml <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> HtmlToPdfElement<span style='color:#808030; '>(</span>footerHtmlUrl<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set the HTML element to fit the container height</span>
    footerHtml<span style='color:#808030; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add HTML element to footer</span>
    pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>footerHtml<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add page numbering</span>
    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>addPageNumbers<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// Create a text element with page numbering place holders &amp;p; and &amp; P;</span>
        TextElement footerText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>30</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page &amp;p; of &amp;P;  </span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
            <span style='color:#800000; font-weight:bold; '>new</span> System<span style='color:#808030; '>.</span>Drawing<span style='color:#808030; '>.</span>Font<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>new</span> System<span style='color:#808030; '>.</span>Drawing<span style='color:#808030; '>.</span>FontFamily<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Times New Roman</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> System<span style='color:#808030; '>.</span>Drawing<span style='color:#808030; '>.</span>GraphicsUnit<span style='color:#808030; '>.</span>Point<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Align the text at the right of the footer</span>
        footerText<span style='color:#808030; '>.</span>TextAlign <span style='color:#808030; '>=</span> HorizontalTextAlign<span style='color:#808030; '>.</span>Right<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Set page numbering text color</span>
        footerText<span style='color:#808030; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Navy<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Embed the text element font in PDF</span>
        footerText<span style='color:#808030; '>.</span>EmbedSysFont <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add the text element to footer</span>
        pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>footerText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>

    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>drawFooterLine<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#800000; font-weight:bold; '>float</span> footerWidth <span style='color:#808030; '>=</span> pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>Width<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Create a line element for the top of the footer</span>
        LineElement footerLine <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> footerWidth<span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Set line color</span>
        footerLine<span style='color:#808030; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Gray<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add line element to the bottom of the footer</span>
        pdfDocument<span style='color:#808030; '>.</span>Footer<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>footerLine<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>

<span style='color:#696969; '>/// &lt;summary></span>
<span style='color:#696969; '>/// Draw the alternative page header elements</span>
<span style='color:#696969; '>/// &lt;/summary></span>
<span style='color:#696969; '>/// &lt;param name="headerTemplate">The page header template&lt;/param></span>
<span style='color:#696969; '>/// &lt;param name="drawHeaderLine">A flag indicating if a line should be drawn at the bottom of the header&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>private</span> <span style='color:#800000; font-weight:bold; '>void</span> DrawAlternativePageHeader<span style='color:#808030; '>(</span>Template headerTemplate<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>bool</span> drawHeaderLine<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>string</span> headerHtmlUrl <span style='color:#808030; '>=</span> Server<span style='color:#808030; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>~/DemoAppFiles/Input/HTML_Files/Header_Alt_HTML.html</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Create a HTML element to be added in header</span>
    HtmlToPdfElement headerHtml <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> HtmlToPdfElement<span style='color:#808030; '>(</span>headerHtmlUrl<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set the HTML element to fit the container height</span>
    headerHtml<span style='color:#808030; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add HTML element to header</span>
    headerTemplate<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>headerHtml<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>drawHeaderLine<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#800000; font-weight:bold; '>float</span> headerWidth <span style='color:#808030; '>=</span> headerTemplate<span style='color:#808030; '>.</span>Width<span style='color:#800080; '>;</span>
        <span style='color:#800000; font-weight:bold; '>float</span> headerHeight <span style='color:#808030; '>=</span> headerTemplate<span style='color:#808030; '>.</span>Height<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Create a line element for the bottom of the header</span>
        LineElement headerLine <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> headerWidth<span style='color:#808030; '>,</span> headerHeight <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Set line color</span>
        headerLine<span style='color:#808030; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Gray<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add line element to the bottom of the header</span>
        headerTemplate<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>headerLine<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>

<span style='color:#696969; '>/// &lt;summary></span>
<span style='color:#696969; '>/// Draw the alternative page footer elements</span>
<span style='color:#696969; '>/// &lt;/summary></span>
<span style='color:#696969; '>/// &lt;param name="htmlToPdfConverter">The HTML to PDF Converter object&lt;/param></span>
<span style='color:#696969; '>/// &lt;param name="addPageNumbers">A flag indicating if the page numbering is present in footer&lt;/param></span>
<span style='color:#696969; '>/// &lt;param name="drawFooterLine">A flag indicating if a line should be drawn at the top of the footer&lt;/param></span>
<span style='color:#800000; font-weight:bold; '>private</span> <span style='color:#800000; font-weight:bold; '>void</span> DrawAlternativePageFooter<span style='color:#808030; '>(</span>Template footerTemplate<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>bool</span> addPageNumbers<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>bool</span> drawFooterLine<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>string</span> footerHtmlUrl <span style='color:#808030; '>=</span> Server<span style='color:#808030; '>.</span>MapPath<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>~/DemoAppFiles/Input/HTML_Files/Footer_Alt_HTML.html</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Create a HTML element to be added in footer</span>
    HtmlToPdfElement footerHtml <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> HtmlToPdfElement<span style='color:#808030; '>(</span>footerHtmlUrl<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set the HTML element to fit the container height</span>
    footerHtml<span style='color:#808030; '>.</span>FitHeight <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add HTML element to footer</span>
    footerTemplate<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>footerHtml<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Add page numbering</span>
    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>addPageNumbers<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// Create a text element with page numbering place holders &amp;p; and &amp; P;</span>
        TextElement footerText <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> TextElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>30</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Page &amp;p; of &amp;P;</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
            <span style='color:#800000; font-weight:bold; '>new</span> System<span style='color:#808030; '>.</span>Drawing<span style='color:#808030; '>.</span>Font<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>new</span> System<span style='color:#808030; '>.</span>Drawing<span style='color:#808030; '>.</span>FontFamily<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Times New Roman</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span><span style='color:#808030; '>,</span> System<span style='color:#808030; '>.</span>Drawing<span style='color:#808030; '>.</span>GraphicsUnit<span style='color:#808030; '>.</span>Point<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Align the text at the right of the footer</span>
        footerText<span style='color:#808030; '>.</span>TextAlign <span style='color:#808030; '>=</span> HorizontalTextAlign<span style='color:#808030; '>.</span>Left<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Set page numbering text color</span>
        footerText<span style='color:#808030; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Navy<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Embed the text element font in PDF</span>
        footerText<span style='color:#808030; '>.</span>EmbedSysFont <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>true</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add the text element to footer</span>
        footerTemplate<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>footerText<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>

    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>drawFooterLine<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#800000; font-weight:bold; '>float</span> footerWidth <span style='color:#808030; '>=</span> footerTemplate<span style='color:#808030; '>.</span>Width<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Create a line element for the top of the footer</span>
        LineElement footerLine <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> LineElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> footerWidth<span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Set line color</span>
        footerLine<span style='color:#808030; '>.</span>ForeColor <span style='color:#808030; '>=</span> Color<span style='color:#808030; '>.</span>Gray<span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Add line element to the bottom of the footer</span>
        footerTemplate<span style='color:#808030; '>.</span>AddElement<span style='color:#808030; '>(</span>footerLine<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>
</pre>
</span>